/**
 * 基础异常类
 * 所有自定义异常都应继承此类
 */
export class BaseException extends Error {
  /**
   * HTTP状态码
   */
  public status: number

  /**
   * 业务错误码
   */
  public errorCode: number

  /**
   * 错误消息
   */
  public message: string

  /**
   * 错误详情（可选）
   */
  public details?: any
  code: number | undefined

  /**
   * 构造函数
   * @param message 错误消息
   * @param status HTTP状态码，默认为500
   * @param errorCode 业务错误码，默认为50000
   * @param details 错误详情
   */
  constructor(
    message: string,
    status: number = 500,
    errorCode: number = 50000,
    details?: any
  ) {
    super(message)
    this.name = this.constructor.name
    this.status = status
    this.errorCode = errorCode
    this.message = message
    this.details = details

    // 捕获堆栈跟踪
    Error.captureStackTrace(this, this.constructor)
  }
}
